#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Created by master on 2017/3/5
# python不支持多态  只能折中实现
class Animal(object):
    def __init__(self, name):
        self.name = name

    def talk(self):
        raise NotImplementedError("Subclass must implements abstract method")


class Cat(Animal):
    def talk(self):
        return "Meow!"


class Dog(Animal):

    def talk(self):
        return "Woof! Woof!"

# 多态的折中实现1
def animal_talk(ani):
    print(ani.talk())

d = Dog("sanjiangMei")
c = Cat("sanjiangYuan")

animal_talk(d)
animal_talk(c)

'''
# 多态的折中实现2
animals = [Cat("Missy"), Dog("Lassie")]

for animal in animals:
    print(animal.name + ":" + animal.talk())
'''
